
package com.jf.cloud.distribution.controller.platform;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.distribution.dto.DistributionUserWalletDTO;
import com.jf.cloud.distribution.model.DistributionUserWallet;
import com.jf.cloud.distribution.service.DistributionUserWalletService;
import com.jf.cloud.distribution.vo.DistributionUserWalletVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分销员钱包信息
 *
 * @author zz
 * @date 2021-08-09 14:14:10
 */
@RestController("platformDistributionUserWalletController")
@RequestMapping("/p/distribution_user_wallet")
@Tag(name = "分销员钱包信息")
public class DistributionUserWalletController {

    @Autowired
    private DistributionUserWalletService distributionUserWalletService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取分销员钱包信息列表" , description = "分页获取分销员钱包信息列表")
    public ServerResponseEntity<PageVO<DistributionUserWallet>> page(@Valid PageDTO pageDTO) {
        PageVO<DistributionUserWallet> distributionUserWalletPage = distributionUserWalletService.page(pageDTO);
        return ServerResponseEntity.success(distributionUserWalletPage);
    }

    @GetMapping("/wallet_page")
    @Operation(summary = "获取分销员钱包信息列表" , description = "分页获取分销员钱包信息列表")
    public ServerResponseEntity<PageVO<DistributionUserWalletVO>> walletPage(@Valid PageDTO pageDTO,String userMobile) {
        PageVO<DistributionUserWalletVO> distributionUserWalletPage = distributionUserWalletService.walletPage(pageDTO, userMobile);
        return ServerResponseEntity.success(distributionUserWalletPage);
    }

    @GetMapping
    @Operation(summary = "获取分销员钱包信息" , description = "根据walletId获取分销员钱包信息")
    public ServerResponseEntity<DistributionUserWallet> getByWalletId(@RequestParam Long walletId) {
        return ServerResponseEntity.success(distributionUserWalletService.getByWalletId(walletId));
    }

    @PutMapping
    @Operation(summary = "更新分销员钱包信息" , description = "更新分销员钱包信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody DistributionUserWalletDTO distributionUserWalletDTO) {
        Long userId = AuthUserContext.get().getUserId();
        distributionUserWalletService.updateWallet(distributionUserWalletDTO, userId);
        return ServerResponseEntity.success();
    }

}
